//
//  STViewController.m
//  SwipeTableView
//
//  Created by Roy lee on 16/4/1.
//  Copyright © 2016年 Roy lee. All rights reserved.
//

#import "STViewController.h"
#import "CustomTableView.h"
#import "CustomCollectionView.h"
#import "CustomSegmentControl.h"
#import "UIView+STFrame.h"
#import "STImageController.h"
#import "STTransitions.h"
#import "STRefresh.h"
#import <objc/message.h>

/** 自定义控件 */
#import "SwipeTbViewNav.h"
#import "SKUDefultQuestionNewTB.h"
#import "SKUDetailTbv_V4.h"
#import "AcceptPriceListModel.h"



@interface STViewController ()<SwipeTableViewDataSource,SwipeTableViewDelegate,UIGestureRecognizerDelegate,UIViewControllerTransitioningDelegate>

/** 头部图片加载 */
@property (nonatomic, strong) STHeaderView * tableViewHeader;


/** 第三方给的例子没用 */
//@property (nonatomic, strong) CustomTableView * tableView;
//@property (nonatomic, strong) CustomCollectionView * collectionView;
@property (nonatomic, strong) NSMutableDictionary * dataDic;


/** 逻辑处理 */
@property (nonatomic, assign)BOOL Questionstate;//当改变询价状态时候（1个item 还是2item）发生改变


/** 自定义控件 */

/** 询价页 */
@property (nonatomic, strong) SKUDefultQuestionNewTB * QuestionNewTB;

/**  走势图 */
@property (nonatomic, strong) SKUDetailTbv_V4 * skuDetailTB;

//导航栏
@property (nonatomic, strong) SwipeTbViewNav * nav;





@end

@implementation STViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.type = 3;

//    if (@available(iOS 11.0, *)) {
//        self.skuDetailTB.contentInsetAdjustmentBehavior =   UIScrollViewContentInsetAdjustmentNever;
//        self.QuestionNewTB.contentInsetAdjustmentBehavior =   UIScrollViewContentInsetAdjustmentNever;
//
//
//    } else {
//        self.automaticallyAdjustsScrollViewInsets = NO;
//    }
    
}

-(SwipeTbViewNav *)nav{
    if (!_nav) {
        _nav = [[SwipeTbViewNav alloc]initWithFrame:CGRectMake(0, 0, kScreenW,NaviHeight)];
        @weakify(self);
        [_nav setBlock:^{
            @strongify(self);
            [self reloaddata];
            //            NSLog(@"开始询价");
            self.Questionstate = NO;
//            [self.skuDetailTB refreshData];
        }];
    }
    return _nav;
}

-(void)setConfiguration{
    
//    self.index = 1;
    BOOL disableBarScroll = _type == STControllerTypeDisableBarScroll;
    BOOL hiddenNavigationBar = _type == STControllerTypeHiddenNavBar;
    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
    
    // init swipetableview3
    self.swipeTableView = [[SwipeTableView alloc]initWithFrame:CGRectMake(0, NaviHeight, kScreenW, kScreenH-NaviHeight)];
    _swipeTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    _swipeTableView.delegate = self;
    _swipeTableView.dataSource = self;
    _swipeTableView.shouldAdjustContentSize = YES;
    _swipeTableView.swipeHeaderView = disableBarScroll?nil:self.tableViewHeader;
    _swipeTableView.swipeHeaderBar = nil;
    _swipeTableView.swipeHeaderBarScrollDisabled = disableBarScroll;
    if (hiddenNavigationBar) {
        _swipeTableView.swipeHeaderTopInset = 0;
    }
    [self.view addSubview:_swipeTableView];

    [self.navigationController.navigationBar setTintColor:RGBColor(256, 256, 256)];
    
    [self.navigationController.navigationBar setHidden:YES];
    // edge gesture
    [_swipeTableView.contentView.panGestureRecognizer requireGestureRecognizerToFail:self.screenEdgePanGestureRecognizer];
    
    // init data
    _dataDic = [@{} mutableCopy];
    
    // 根据滚动后的下标请求数据
    //    [self getDataAtIndex:0];
    
    // 一次性请求所有item的数据
    [self getAllData];
    [self.view addSubview:self.nav];

}

- (UIScreenEdgePanGestureRecognizer *)screenEdgePanGestureRecognizer {
    UIScreenEdgePanGestureRecognizer *screenEdgePanGestureRecognizer = nil;
    if (self.navigationController.view.gestureRecognizers.count > 0) {
        for (UIGestureRecognizer *recognizer in self.navigationController.view.gestureRecognizers) {
            if ([recognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
                screenEdgePanGestureRecognizer = (UIScreenEdgePanGestureRecognizer *)recognizer;
                break;
            }
        }
    }
    return screenEdgePanGestureRecognizer;
}

#pragma mark - Header & Bar

-(STHeaderView *)tableViewHeader{
    if (!_tableViewHeader) {
        _tableViewHeader = [[STHeaderView alloc]init];
        _tableViewHeader.frame = CGRectMake(0, 0, kScreenWidth, kScreenWidth/350.0*300);
        _tableViewHeader.backgroundColor = [UIColor whiteColor];
        _tableViewHeader.layer.masksToBounds = YES;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHeader:)];
        [self.headerImageView addGestureRecognizer:tap];
    }
    return _tableViewHeader;
}
-(UIImageView *)headerImageView{
    if (!_headerImageView) {
        _headerImageView = [[UIImageView alloc]init];
        _headerImageView.contentMode = 1;
        _headerImageView.userInteractionEnabled = YES;
        _headerImageView.frame =  CGRectMake(0, 0, kScreenWidth, kScreenWidth/350.0*300);
        _headerImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    }
    return _headerImageView;
}


- (CustomSegmentControl * )segmentBar {
    if (nil == _segmentBar) {
        /** 设置item 个数 */

//        self.index = @[@"Item0",@"Item1"].count;
        self.segmentBar = [[CustomSegmentControl alloc]initWithItems:self.arr];
        _segmentBar.st_size = CGSizeMake(kScreenWidth, 40);
        _segmentBar.font = [UIFont systemFontOfSize:15];
        _segmentBar.textColor = RGBColor(100, 100, 100);
        _segmentBar.selectedTextColor = RGBColor(0, 0, 0);
        _segmentBar.backgroundColor = [UIColor whiteColor];
        _segmentBar.selectionIndicatorColor = [UIColor whiteColor];
//        _segmentBar.selectedSegmentIndex = _swipeTableView.currentItemIndex;
        _segmentBar.selectedSegmentIndex = 0;

        [_segmentBar addTarget:self action:@selector(changeSwipeViewIndex:) forControlEvents:UIControlEventValueChanged];
    }
    return _segmentBar;
}



- (void)tapHeader:(UITapGestureRecognizer *)tap {
    STImageController * imageVC = [[STImageController alloc]init];
    imageVC.transitioningDelegate = self;
    [self presentViewController:imageVC animated:YES completion:nil];
}

// tap to change header's frame
- (void)_tapHeader:(UITapGestureRecognizer *)tap {
    
    CGFloat changeHeight = 50; // or -50, it will be parallax.
    UIScrollView * currentItem = _swipeTableView.currentItemView;
#if !defined(ST_PULLTOREFRESH_HEADER_HEIGHT)
    CGPoint contentOffset = currentItem.contentOffset;
    UIEdgeInsets inset = currentItem.contentInset;
    inset.top += changeHeight;
    contentOffset.y -= changeHeight;  // if you want the header change height from up, not do this.
    
    NSMutableDictionary * contentOffsetQuene = [self.swipeTableView valueForKey:@"contentOffsetQuene"];
    [contentOffsetQuene removeAllObjects];
    
    [UIView animateWithDuration:.35f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.tableViewHeader.st_height += changeHeight;
        currentItem.contentInset = inset;
        currentItem.contentOffset = contentOffset;
    } completion:^(BOOL finished) {
        [self.swipeTableView setValue:@(self.tableViewHeader.st_height) forKey:@"headerInset"];
    }];
    
#else
    UIView * tableHeaderView = ((UITableView *)currentItem).tableHeaderView;
    tableHeaderView.st_height += changeHeight;
    
    [UIView animateWithDuration:.35f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.tableViewHeader.st_height += changeHeight;
        [currentItem setValue:tableHeaderView forKey:@"tableHeaderView"];
    } completion:^(BOOL finished) {
        [self.swipeTableView setValue:@(self.tableViewHeader.st_height) forKey:@"headerInset"];
    }];
#endif
    
}

- (void)shimmerHeaderTitle:(UILabel *)title {
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:0.75f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        title.transform = CGAffineTransformMakeScale(0.98, 0.98);
        title.alpha = 0.3;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.75f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            title.alpha = 1.0;
            title.transform = CGAffineTransformIdentity;
        } completion:^(BOOL finished) {
            [weakSelf shimmerHeaderTitle:title];
        }];
    }];
}

- (void)setSwipeTableHeader:(UIBarButtonItem *)barItem {
    if (!_swipeTableView.swipeHeaderView) {
        _swipeTableView.swipeHeaderView = self.tableViewHeader;
        [_swipeTableView reloadData];
        
        UIBarButtonItem * rightBarItem = [[UIBarButtonItem alloc]initWithTitle:@"- Header" style:UIBarButtonItemStylePlain target:self action:@selector(setSwipeTableHeader:)];
        self.navigationItem.rightBarButtonItem = rightBarItem;
    }else {
        _swipeTableView.swipeHeaderView = nil;
        
        UIBarButtonItem * rightBarItem = [[UIBarButtonItem alloc]initWithTitle:@"+ Header" style:UIBarButtonItemStylePlain target:self action:@selector(setSwipeTableHeader:)];
        self.navigationItem.rightBarButtonItem = rightBarItem;
    }
}

- (void)setSwipeTableBar:(UIBarButtonItem *)barItem {
    self.swipeTableView.swipeHeaderBar = nil;

//    if (!_swipeTableView.swipeHeaderBar) {
//        _swipeTableView.swipeHeaderBar = self.segmentBar;
//        _swipeTableView.scrollEnabled  = YES;
//
//        UIBarButtonItem * leftBarItem = [[UIBarButtonItem alloc]initWithTitle:@"- Bar" style:UIBarButtonItemStylePlain target:self action:@selector(setSwipeTableBar:)];
//        self.navigationItem.leftBarButtonItem = leftBarItem;
//    }else {
//        _swipeTableView.swipeHeaderBar = nil;
//        _swipeTableView.scrollEnabled  = NO;
//
//        UIBarButtonItem * leftBarItem = [[UIBarButtonItem alloc]initWithTitle:@"+ Bar" style:UIBarButtonItemStylePlain target:self action:@selector(setSwipeTableBar:)];
//        self.navigationItem.leftBarButtonItem = leftBarItem;
//    }
}

//- (CustomTableView *)tableView {
//    if (nil == _tableView) {
//        _tableView = [[CustomTableView alloc]initWithFrame:_swipeTableView.bounds style:UITableViewStylePlain];
//        _tableView.backgroundColor = [UIColor whiteColor];
//
////        _tableView.backgroundColor = RGBColor(255, 255, 225);
//    }
//    return _tableView;
//}

-(SKUDefultQuestionNewTB *)QuestionNewTB{
    if (!_QuestionNewTB) {
        _QuestionNewTB = [[SKUDefultQuestionNewTB alloc]initWithFrame:_swipeTableView.bounds];
        _QuestionNewTB.backgroundColor = [UIColor whiteColor];
        _QuestionNewTB.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [self reloaddata];
          
        }];
        @weakify(self);
        [_QuestionNewTB setBlock:^{
            @strongify(self);
            [self reloaddata];
            self.Questionstate = NO;
        }];
    }
    return _QuestionNewTB;
}

-(SKUDetailTbv_V4 *)skuDetailTB{
    if (!_skuDetailTB) {
        _skuDetailTB = [[SKUDetailTbv_V4 alloc]initializeFrame:_swipeTableView.bounds isMj:0 isEstimatedRowHeight:YES addRegisterNib:@[@"SKUDetailTbv_V4_Head_Title_Cell",@"SKUDetailTbv_V4_Price_Chart_Cell",@"SKUDetailTbv_V4_Buy_Cell",@"SKUDetailDefultCell_V4",@"SKUDetailTbv_V4_enquiryPrice_Cell"]];
//        _skuDetailTB = [[SKUDetailTbv_V4 alloc]initWithFrame:_swipeTableView.bounds];
        _skuDetailTB.backgroundColor = [UIColor whiteColor];
        @weakify(self);
       
        [_skuDetailTB setOpenQuestion:^{
             @strongify(self);
            [Tools showTips:@"开始询价"];
            [self reloaddata];
//            NSLog(@"开始询价");
            self.Questionstate = NO;
        }];
        _skuDetailTB.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [self reloaddata];
        }];
    }
    return _skuDetailTB;
}



//- (CustomCollectionView *)collectionView {
//    if (nil == _collectionView) {
//        _collectionView = [[CustomCollectionView alloc]initWithFrame:_swipeTableView.bounds];
//        _collectionView.backgroundColor = [UIColor whiteColor];
//    }
//    return _collectionView;
//}

- (void)changeSwipeViewIndex:(UISegmentedControl *)seg {
    [_swipeTableView scrollToItemAtIndex:seg.selectedSegmentIndex animated:NO];
    // request data at current index
    [self getDataAtIndex:seg.selectedSegmentIndex];
}

#pragma mark - Data Reuqest

// 请求数据（根据视图滚动到相应的index后再请求数据）
- (void)getDataAtIndex:(NSInteger)index {
    if (nil != _dataDic[@(index)]) {
        return;
    }
    NSInteger numberOfRows = 0;
    switch (index) {
        case 0:
            numberOfRows = _type == STControllerTypeNormal?8:10;
            break;
        case 1:
            numberOfRows = _type == STControllerTypeNormal?10:8;
            break;
        case 2:
            numberOfRows = _type == STControllerTypeNormal?5:6;
            break;
        case 3:
            numberOfRows = _type == STControllerTypeNormal?12:12;
            break;
        default:
            break;
    }
    // 请求数据后刷新相应的item
    ((void (*)(void *, SEL, NSNumber *, NSInteger))objc_msgSend)((__bridge void *)(self.swipeTableView.currentItemView),@selector(refreshWithData:atIndex:), @(numberOfRows),index);
    // 保存数据
    [_dataDic setObject:@(numberOfRows) forKey:@(index)];
}

// 请求数据（一次性获取所有item的数据）
- (void)getAllData {
    if (_type == STControllerTypeNormal) {
        [_dataDic setObject:@(8) forKey:@(0)];
        [_dataDic setObject:@(10) forKey:@(1)];
        [_dataDic setObject:@(5) forKey:@(2)];
        [_dataDic setObject:@(12) forKey:@(3)];
    }else {
        [_dataDic setObject:@(10) forKey:@(0)];
        [_dataDic setObject:@(12) forKey:@(1)];
        [_dataDic setObject:@(8) forKey:@(2)];
        [_dataDic setObject:@(14) forKey:@(3)];
    }
}


#pragma mark - SwipeTableView M

- (NSInteger)numberOfItemsInSwipeTableView:(SwipeTableView *)swipeView {
    /** 横滑view的个数 */
    return self.arr.count;
}

/** 添加滑动试图页面 */
- (UIScrollView *)swipeTableView:(SwipeTableView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIScrollView *)view {
    switch (_type) {
        case STControllerTypeNormal:
        {
            CustomTableView * tableView = (CustomTableView *)view;
            // 重用
            if (nil == tableView) {
                tableView = [[CustomTableView alloc]initWithFrame:swipeView.bounds style:UITableViewStylePlain];
                tableView.backgroundColor = [UIColor whiteColor];
            }
            
            // 获取当前index下item的数据，进行数据刷新
            id data = _dataDic[@(index)];
            [tableView refreshWithData:data atIndex:index];
            
            view = tableView;
        }
            break;
        case STControllerTypeHybrid:
        case STControllerTypeDisableBarScroll:
        case STControllerTypeHiddenNavBar:
        {
            
            if ([self.model.myEnquiryFlag isEqualToString:@"1"]) {
                if (index == 1) {
                    // 懒加载保证同样类型的item只创建一次，以达到重用
                    SKUDetailTbv_V4 * tableView = self.skuDetailTB;
                    tableView.goodId = self.goodId;
                    
                    // 获取当前index下item的数据，进行数据刷新
                    id data = _dataDic[@(index)];
                    [tableView refreshWithData:data atIndex:index];
                    
                    view = tableView;
                    
                    
                }else{
                    // 懒加载保证同样类型的item只创建一次，以达到重用
                    
                    SKUDefultQuestionNewTB * tableView = self.QuestionNewTB;
                    tableView.goodId = self.goodId;
                    
                    // 获取当前index下item的数据，进行数据刷新
                    id data = _dataDic[@(index)];
                    [tableView refreshWithData:data atIndex:index];
                    
                    view = tableView;
                }
            }else{
                if (index == 0) {
                    // 懒加载保证同样类型的item只创建一次，以达到重用
                    SKUDetailTbv_V4 * tableView = self.skuDetailTB;
                    tableView.goodId = self.goodId;
                    
                    // 获取当前index下item的数据，进行数据刷新
                    id data = _dataDic[@(index)];
                    [tableView refreshWithData:data atIndex:index];
                    
                    view = tableView;
                    
                    
                }else{
                    // 懒加载保证同样类型的item只创建一次，以达到重用
                    
                    SKUDefultQuestionNewTB * tableView = self.QuestionNewTB;
                    tableView.goodId = self.goodId;
                    
                    // 获取当前index下item的数据，进行数据刷新
                    id data = _dataDic[@(index)];
                    [tableView refreshWithData:data atIndex:index];
                    
                    view = tableView;
                }
            }
            
            
            
            // 混合的itemview只有同类型的item采用重用
//            if (index == 0 || index == 2) {
//
//                // 懒加载保证同样类型的item只创建一次，以达到重用
//                CustomTableView * tableView = self.tableView;
//
//                // 获取当前index下item的数据，进行数据刷新
//                id data = _dataDic[@(index)];
//                [tableView refreshWithData:data atIndex:index];
//
//                view = tableView;
//            }else {
//
//                CustomCollectionView * collectionView = self.collectionView;
//
//                // 获取当前index下item的数据，进行数据刷新
//                id data = _dataDic[@(index)];
//                [collectionView refreshWithData:data atIndex:index];
//
//                view = self.collectionView;
//            }
            
        }
            break;
        default:
            break;
    }
    
    // 在没有设定下拉刷新宏的条件下，自定义的下拉刷新需要做 refreshheader 的 frame 处理
    [self configRefreshHeaderForItem:view];
    
    return view;
}

// swipetableView index变化，改变seg的index
- (void)swipeTableViewCurrentItemIndexDidChange:(SwipeTableView *)swipeView {
    _segmentBar.selectedSegmentIndex = swipeView.currentItemIndex;
}

// 滚动结束请求数据
- (void)swipeTableViewDidEndDecelerating:(SwipeTableView *)swipeView {
    [self getDataAtIndex:swipeView.currentItemIndex];
}

/**
 *  以下两个代理，在未定义宏 #define ST_PULLTOREFRESH_HEADER_HEIGHT，并自定义下拉刷新的时候，必须实现
 *  如果设置了下拉刷新的宏，以下代理可根据需要实现即可
 */
- (BOOL)swipeTableView:(SwipeTableView *)swipeTableView shouldPullToRefreshAtIndex:(NSInteger)index {
    return YES;
}

- (CGFloat)swipeTableView:(SwipeTableView *)swipeTableView heightForRefreshHeaderAtIndex:(NSInteger)index {
    return kSTRefreshHeaderHeight;
}

/**
 *  采用自定义修改下拉刷新，此时不会定义宏 #define ST_PULLTOREFRESH_HEADER_HEIGHT
 *  对于一些下拉刷新控件，可能会在`layouSubViews`中设置RefreshHeader的frame。所以，需要在itemView有效的方法中改变RefreshHeader的frame，如 `scrollViewDidScroll:`
 */

- (void)configRefreshHeaderForItem:(UIScrollView *)itemView {
    
    if (_type == STControllerTypeDisableBarScroll) {
        
        itemView.header = nil;
        
        return;
    }
    
#if !defined(ST_PULLTOREFRESH_HEADER_HEIGHT)
    STRefreshHeader * header = itemView.header;
    header.st_y = - (header.st_height + (_segmentBar.st_height + _headerImageView.st_height));
#endif
}



-(void)setGoodId:(NSString *)goodId{
    _goodId = goodId;
    [self reloaddata];
}

-(void)reloaddata{
    
    [[serviceDefualt loadskuDetail:self.goodId reponseObjctClass:[skuDetailModel class]]subscribeNext:^(ResponseData* x) {
        if (x.success) {
            self.model  = (skuDetailModel*)x.responseData;
            if ([self.model.myEnquiryFlag isEqualToString:@"1"]) {
                [self loadList];
            }
        }else{
            [Tools showTips:x.errorInfo];
        }
        
        [self.skuDetailTB.mj_header endRefreshing];
        [self.QuestionNewTB.mj_header endRefreshing];
    }];
    
}


-(void)loadList{
    [[serviceDefualt loadGetBizPriceInfoList:self.goodId page:0 userEnquiryId:self.model.userEnquiryId reponseObjctClass:nil]subscribeNext:^(ResponseData* x) {
        /* TODO: ================= 收到报价 =================*/
        
        if (x.success) {

            NSArray *arr = x.responseRawData[@"data"];
                        
            self.QuestionNewTB.GetBizPriceInfoArrM = [[NSMutableArray alloc]init];
            if (arr.count>0) {
                for (NSDictionary *dic in arr) {
                    AcceptPriceListModel *model = [AcceptPriceListModel yy_modelWithJSON:dic];
                    [self.QuestionNewTB.GetBizPriceInfoArrM addObject:model];
                }
            }
          
            [self.QuestionNewTB reloadData];

//
//            [self setNoMoreDataBg:YES NoDataState:NoMoreDataStateDefault];
//
//            if (arr.count == 0 ) {
//                if (self.page == 0) {
//                    self.GetBizPriceInfoArrM = [[NSMutableArray alloc]init];
//                    [self setNoMoreDataBg:NO NoDataState:NoMoreDataStateDefault];
//                    self.noMoreDateView.title.text = @"没有更多数据";
//                    [Tools showTips:@"暂无更多数据"];
//                }
//                [self endRefreshing];
//                [self.mj_footer endRefreshingWithNoMoreData];
//                return ;
//            }else{
//                if (self.page == 0) {
//                    self.GetBizPriceInfoArrM = [[NSMutableArray alloc]init];
//                    for (NSDictionary *dic in arr) {
//                        AcceptPriceListModel *model = [AcceptPriceListModel yy_modelWithJSON:dic];
//                        [self.GetBizPriceInfoArrM addObject:model];
//                    }
//                }else{
//                    for (NSDictionary *dic in arr) {
//                        AcceptPriceListModel *model = [AcceptPriceListModel yy_modelWithJSON:dic];
//                        [self.GetBizPriceInfoArrM addObject:model];
//                    }
//                }
//            }
            
            
            
        }else{
            [Tools showTips:x.errorInfo];
        }
        
//
//        [self reloadData];
//        [self endRefreshing];
    }];
}

-(void)setModel:(skuDetailModel *)model{
    _model = model;

//    if ([model.myEnquiryFlag isEqualToString:@"1"]) {
//        self.arr = @[@"我的询价",@"表款详情"];
//
////        self.segmentBar.hidden = NO;
//        _swipeTableView.swipeHeaderBar = self.segmentBar;
//        _swipeTableView.scrollEnabled  = YES;
////        self.segmentBar = nil;
////        self.swipeTableView.swipeHeaderBar = nil;
////        self.swipeTableView.scrollEnabled  = NO;
//    }else{
//        self.arr = @[@"表款详情"];
//        _swipeTableView.swipeHeaderBar = nil;
//        _swipeTableView.scrollEnabled  = NO;
////        self.segmentBar.hidden = YES;
////        self.segmentBar = nil;
////        self.swipeTableView.swipeHeaderBar = nil;
////        self.swipeTableView.scrollEnabled  = NO;
//    }
    



    self.nav.model = model;

    [self.tableViewHeader addSubview:self.headerImageView];

    if (!self.st) {
        self.st = YES;
        _swipeTableView = nil;
        [self setConfiguration];
        NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,self.model.imageDefault];
//        self.headerImageView = [[UIImageView alloc]init];
        [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"ucg_img_loding"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            
//            static dispatch_once_t onceToken;
//            dispatch_async(dispatch_get_global_queue(0,0), ^{
//                dispatch_async(dispatch_get_main_queue(), ^{
            
                    
//                });
//            });
            
        }];
    }
    
    if (!self.Questionstate) {
        self.Questionstate = YES;
        if ([model.myEnquiryFlag isEqualToString:@"1"]) {
            self.arr = @[@"我的询价",@"表款详情"];
            _swipeTableView.swipeHeaderBar = self.segmentBar;
            _swipeTableView.scrollEnabled  = YES;
            //        self.segmentBar.hidden = NO;
            
            //        self.segmentBar = nil;
            //        self.swipeTableView.swipeHeaderBar = nil;
            //        self.swipeTableView.scrollEnabled  = NO;
        }else{
            //不滑动
            self.arr = @[@"表款详情"];
            _swipeTableView.swipeHeaderBar = nil;
            _swipeTableView.scrollEnabled  = NO;
            //        self.segmentBar.hidden = YES;
            //        self.segmentBar = nil;
            //        self.swipeTableView.swipeHeaderBar = nil;
            //        self.swipeTableView.scrollEnabled  = NO;
        }
        
    }
    self.QuestionNewTB.model = model;
    self.skuDetailTB.model = model;
    
    
}



/** 不需要了解的部分 */

#pragma mark -

- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    return [[STTransitions alloc]initWithTransitionDuration:0.5f fromView:self.headerImageView isPresenting:NO];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:_type == STControllerTypeHiddenNavBar animated:animated];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    __weak typeof(self) weakSelf = self;
    self.navigationController.interactivePopGestureRecognizer.delegate = weakSelf;
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/** 转场动画 */
#pragma  mark - UIViewControllerTransitioningDelegate

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
                                                                  presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
    
    return [[STTransitions alloc]initWithTransitionDuration:0.55f fromView:self.headerImageView isPresenting:YES];
}

@end
